import os
from kashgari.tasks.labeling import BiLSTM_CRF_Model
from kashgari.tasks.labeling import BiLSTM_Model
from kashgari.tasks.labeling import CNN_LSTM_Model
import embedding
import BIO
import solve
model = BiLSTM_CRF_Model(embedding.bert_embed)
# model = BiLSTM_Model(embedding.bert_embed)
import Reader.wordBIO as W_R


#1 sentence 2 words

runList = []
trainxlist = []
trainylist = []
reslist = []

list = W_R.wordBIO()
# print(len(list))
# print(list[0])
# print(list[1])
for runli in list:
    trainxlist.append(runli[0])
    trainylist.append(runli[1])
print("list赋值完成============")

# runListlen = int(len(list)/5*4)  #分成五份取四份训练
# RestLen = len(list) - runListlen
#
# train_x = trainxlist[0:runListlen]
# train_y = trainylist[0:runListlen]
train_x = trainxlist
train_y = trainylist
valid_x,valid_y = train_x,train_y
test_x,test_y = train_x,train_y
# valid_x,valid_y = train_x[runListlen:],train_y[runListlen:]
# test_x,test_y = train_x[runListlen:],train_y[runListlen:]

model.fit(train_x,
          train_y,
          x_validate=valid_x,
          y_validate=valid_y,
          epochs=10,
          batch_size=60)
result = model.evaluate(test_x,test_y)
model.predict(train_x)
model.save('NLP/NLP/en')


